package com.jiaquyun.jcyx.jetpack.api

import com.jiaquyun.jcyx.app.JCApplication
import com.jiaquyun.jcyx.base.BaseManager
import com.jiaquyun.jcyx.entity.*
import com.jiaquyun.jcyx.main.cart.CartSettlementActivity
import com.module.lemlin.http.HttpResponseData
import rxhttp.RxHttp
import rxhttp.await


class OrderRepository : BaseManager() {

    /**
     * 提交订单
     * */
    suspend fun orderSubmit(
        orderData: OrderData
    ): OrderSubmitResponse = RxHttp.postBody("/api/order/submitOrder")
        .setJsonBody(orderData)
        .await()

    /**
     * 订单支付
     * */
    suspend fun orderPay(
        orderId: String, payType: String,platform:String
    ): OrderPayResponse = RxHttp.postForm("/api/order/payOrder")
        .add("order_id", orderId)
        .add("pay_type", payType)
        .add("platform",platform)
        .await()

    /**
     * 订单取消
     * */
    suspend fun orderCancel(orderId: String): HttpResponseData =
        RxHttp.postForm("/api/order/cancelOrder")
            .add("order_id", orderId)
            .await()

    /**
     * 确认收货
     * */
    suspend fun orderConfirm(orderId: String): HttpResponseData =
        RxHttp.postForm("/api/order/confirm")
            .add("order_id", orderId)
            .await()

    /**
     * 我的订单
     * */
    suspend fun orderIndex(
        type: String, page: String, rows: String
    ): OrderListResponse = RxHttp.postForm("/api/order/index")
        .add("type", type)
        .add("page", page)
        .add("rows", rows)
        .await()

    /**
     * 订单详情
     * */
    suspend fun orderDetail(orderId: String): OOrderDetailsResponse =
        RxHttp.postForm("/api/order/detail")
            .add("order_id", orderId)
            .await()

    /**
     * 申请退款
     * */
    suspend fun orderApplyRefund(
        orderId: String, goodsId: String
    ): OOrderDetailsResponse = RxHttp.postForm("/api/order/applyRefund")
        .add("order_id", orderId)
        .add("goods_id", goodsId)
        .await()

    /**
     * 提交申请退款
     * */
    suspend fun orderSubmitRefund(
        orderId: String,
        goodsId: String,
        reason: String,
        images: String,
        goodsNum: String
    ): HttpResponseData = RxHttp.postForm("/api/order/submitRefund")
        .add("order_id", orderId)
        .add("goods_id", goodsId)
        .add("reason", reason)
        .add("images", images)
        .add("goods_num", goodsNum)
        .await()

    /**
     * 评论
     * */
    suspend fun orderAddComment(orderId: String): HttpResponseData =
        RxHttp.get("/api/order/addComment")
            .add("order_id", orderId)
            .await()

    /**
     * 添加评论
     * */
    suspend fun orderSubmitComment(
        orderId: String, comment: String, riderComment: String
    ): HttpResponseData = RxHttp.postForm("/api/order/submitComment")
        .add("order_id", orderId)
        .add("comment", comment)
        .add("rider_comment", riderComment)
        .await()
}